﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Text;

namespace LandNotepad
{
    public partial class FontStyle : Form
    {
        public FontStyle()
        {
            InitializeComponent();
        }

        private void FontStyle_Load(object sender, EventArgs e)
        {
            //获取字体
            GetFontFamily();
            //获取字形
            GetFontStyle();
            //获取大小
        }

        /// <summary>
        /// 字体类型（宋体、行书、楷体）
        /// </summary>
        private void GetFontFamily()
        {
            //获取此电脑的所有字体
            InstalledFontCollection ifc = new InstalledFontCollection();
            foreach (FontFamily font in ifc.Families)
                this.FFamily.Items.Add(font.Name);
            this.FFamily.SelectedIndex = 0;//设置默认字体
        }

        /// <summary>
        /// 获取字体风格
        /// </summary>
        private void GetFontStyle()
        {
            //获取枚举中的值,返回一个数组
            foreach (System.Drawing.FontStyle fs in Enum.GetValues(typeof(System.Drawing.FontStyle)))
                this.FStyle.Items.Add(fs);
            this.FStyle.SelectedIndex = 0;//设置默认字形
        }

        //定义一个事件委托event事件
        //也就是定义一块虚拟内存，创建一个函数地址
        public event Action<Font> FontSave;//默认为null

        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Sure_Click(object sender, EventArgs e)
        {
            //组织Font返回回去
            String ff = this.FFamily.Text;
            var fsty = (System.Drawing.FontStyle)Enum.Parse(typeof(System.Drawing.FontStyle), this.FStyle.Text);
            float fsize = float.Parse(this.FSize.Value.ToString());
            //获取以选择的样式
            Font fres = new Font(ff, fsize, fsty);
            FontSave(fres);


            this.Close();
        }
    }
}
